﻿using System;
using System.Linq;
using Lyricsgrabber.Core.ID3;
using Lyricsgrabber.Core.ID3.Frames;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Lyricsgrabber.Core.Test
{
  [TestClass]
  public class ID3TagTest
  {
    [TestMethod]
    public void TestID3TagUnicode()
    {
      ID3Tag tag = new ID3Tag(@".\Resources\ID3\ID3Tag Only Unicode.mp3");

      Assert.IsTrue(tag.Frames.Any(f => f is ID3FrameTitle));
      Assert.AreEqual("Invisible Walls", tag.Frames.First(f => f is ID3FrameTitle).ToString());
      
      Assert.IsTrue(tag.Frames.Any(f => f is ID3FrameAlbum));
      Assert.AreEqual("Invisible Walls", tag.Frames.First(f => f is ID3FrameAlbum).ToString());
      
      Assert.IsTrue(tag.Frames.Any(f => f is ID3FrameArtist));
      Assert.AreEqual("Destination's Calling", tag.Frames.First(f => f is ID3FrameArtist).ToString());

      ID3FrameUnsyncedLyrics lyrics = (ID3FrameUnsyncedLyrics) tag.Frames.FirstOrDefault(f => f is ID3FrameUnsyncedLyrics);

      Assert.IsNotNull(lyrics);

      Assert.AreEqual("eng", lyrics.Language);
      Assert.AreEqual("", lyrics.Descriptor);
      Assert.AreEqual(@"Darkness flows around us 
In this vanity we're passing by 
Drawing fancy lines on our 
Empty walls inside 

Chiming bells of decay 
We cannot defy 
Are hunting for more 
To numb the tears we cry 
Timeless is the dawn and the setting sun 
", lyrics.Lyrics);
    }

    [TestMethod]
    public void TestID3TagISO()
    {
      ID3Tag tag = new ID3Tag(@".\Resources\ID3\ID3Tag Only ISO.mp3");

      Assert.IsTrue(tag.Frames.Any(f => f is ID3FrameTitle));
      Assert.AreEqual("Invisible Walls", tag.Frames.First(f => f is ID3FrameTitle).ToString());
   
      Assert.IsTrue(tag.Frames.Any(f => f is ID3FrameAlbum));
      Assert.AreEqual("Invisible Walls", tag.Frames.First(f => f is ID3FrameAlbum).ToString());
    
      Assert.IsTrue(tag.Frames.Any(f => f is ID3FrameArtist));
      Assert.AreEqual("Destination's Calling", tag.Frames.First(f => f is ID3FrameArtist).ToString());

      ID3FrameUnsyncedLyrics lyrics = (ID3FrameUnsyncedLyrics)tag.Frames.FirstOrDefault(f => f is ID3FrameUnsyncedLyrics);

      Assert.IsNotNull(lyrics);

      Assert.AreEqual("eng", lyrics.Language);
      Assert.AreEqual("", lyrics.Descriptor);
      Assert.AreEqual(@"Darkness flows around us 
In this vanity we're passing by 
Drawing fancy lines on our 
Empty walls inside 

Chiming bells of decay 
We cannot defy 
Are hunting for more 
To numb the tears we cry 
Timeless is the dawn and the setting sun 
", lyrics.Lyrics);
    }
  }
}
